package com.heima.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.heima.pojo.TbUser;
import com.heima.mapper.TbUserMapper;
import com.heima.pojo.vo.NodeVo;
import com.heima.pojo.vo.PageResponse;
import com.heima.pojo.vo.UserVo;
import com.heima.service.ITbUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author nan
 * @since 2024-06-11
 */
@Service
public class TbUserServiceImpl extends ServiceImpl<TbUserMapper, TbUser> implements ITbUserService {

    @Autowired
    private TbUserMapper userMapper;

    /**
     * 用户搜索
     *
     * @param pageIndex
     * @param pageSize
     * @param userName
     * @return
     */
    @Override
    public PageResponse<UserVo> getByPage(Integer pageIndex, Integer pageSize, String userName) {

        Page<UserVo> page = new Page<>(pageIndex, pageSize);
        Page<UserVo> userVoPage = userMapper.getByPage(page, userName);
        PageResponse<UserVo> pageResponse = new PageResponse<>();
        pageResponse.setPageIndex(userVoPage.getCurrent());
        pageResponse.setPageSize(userVoPage.getSize());
        pageResponse.setTotalPage(userVoPage.getPages());
        pageResponse.setTotalCount(userVoPage.getTotal());
        pageResponse.setCurrentPageRecords(List.copyOf(userVoPage.getRecords()));
        return pageResponse;
    }
}
